﻿using System;
using System.Collections.Generic;
using System.Linq;
using Backend.JYD.Business;
using Backend.JYD.Model;
using Backend.JYD.Model.Task;

namespace Backend.JYD.BLL.Task
{
    public class TaskModelBLL
    {
        private static readonly IDAL.Task.ITaskModel idal = Factory.DALFactory.CreateEFDAL<IDAL.Task.ITaskModel>("DAL.TaskModelDAL");
        
        public Int64 AddTaskModel(TaskModel info)
        {
            if (string.IsNullOrWhiteSpace(info.TaskName)) return 0;
            var id = idal.AddTaskModel(info);
            TaskManager.ReloadAllTaskModeles();
            return id;
        }

        public bool UpdateTaskModel(TaskModel info)
        {
            if (string.IsNullOrWhiteSpace(info.TaskName)) return false;
            if (info.TaskModeId <= 0) return false;
            var success = idal.UpdateTaskModel(info);
            TaskManager.ReloadAllTaskModeles();
            return success;
        }

        public TaskModel GetTaskModelByTaskModeId(Int64 taskModeId)
        {
            if (taskModeId <= 0) return null;
            var list = TaskManager.LoadAllTaskModeles();
            return list == null ? null : list.ToList().Find(p => p.TaskModeId == taskModeId);
            //return idal.GetTaskModelByTaskModeId(taskModeId);
        }

        public IList<TaskModel> GetTaskModelByTaskModeIds(IList<Int64> taskModeIds)
        {
            if (taskModeIds != null || taskModeIds.Count <= 0) return null;
            var list = TaskManager.LoadAllTaskModeles();
            var temp = list == null ? null : list.Where(p => taskModeIds.Contains(p.TaskModeId));
            return temp == null ? null : temp.ToList();
            //return idal.GetTaskModelByTaskModeIds(taskModeIds);
        }

        public PageInfo<TaskModel> GetTaskModelByPage(PageInfo page)
        {
            var list = TaskManager.LoadAllTaskModeles();
             return new PageInfo<TaskModel>(page, list);
            //return idal.GetTaskModelByPage(page);
        }
    }
}
